/*
 *
 *  ------------------------------------------------------------------
 *  Copyright © 2017 Hangzhou DtDream Technology Co.,Lt d. All rights reserved.
 *  ------------------------------------------------------------------
 *        Product:  EMR
 *    Module Name: NEZHA
 *   Date Created: 17-10-23 下午4:22
 *    Description:
 *  ------------------------------------------------------------------
 *  Modification History
 *  DATE            Name           Description
 *  ------------------------------------------------------------------
 *  2017-10-23      NEZHA EMR
 *  ------------------------------------------------------------------
 * /
 */

package org.xukai.remoting.sdk.web.api;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;

/**
 * Created by moriarty on 17-2-23.
 */
public class RestAPI {
    private static final String VERSION = "/api/v1";
    private static final String MODULE = "sql";

    public final String pathTemplate;
    public final String method;

    RestAPI(String pathTemplate, String method) {
        this.pathTemplate = pathTemplate;
        this.method = method;
    }

    public String toAPIPath(Object... args) {
        return String.format(VERSION + "/projects/%s/" + MODULE + pathTemplate,
                Arrays.stream(args).map(x -> {
                    try {
                        return URLEncoder.encode(x.toString(), "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    }
                }).toArray());
    }
}
